package com.glsc.ngateway.platform.domain;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateTimeDeserializer;
import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer;
import com.glsc.ngateway.common.base.domain.mysql.gateway.platform.Appendix;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.hibernate.annotations.Where;
import org.springframework.format.annotation.DateTimeFormat;

import javax.persistence.*;
import java.io.Serializable;
import java.time.LocalDateTime;
import java.util.List;


/**
 * @author guoj
 * @description: 测试任务
 * @date 2024/7/16 9:37
 */
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Data
@Entity
@Table(name = "t_test_task")
public class TestTask implements Serializable {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "l_id", columnDefinition = "int comment '唯一编号'")
    private Long id;

    @ApiModelProperty(value = "测试流程id")
    @Column(name = "vc_process_id", columnDefinition = "varchar(60) comment '测试流程id'")
    private String processId;
    @ApiModelProperty(value = "测试流程标题")
    @Column(name = "vc_process_title", columnDefinition = "varchar(600) comment '测试流程标题'")
    private String processTitle;

    @ApiModelProperty(value = "需求list")
    @OneToMany(cascade = CascadeType.ALL,fetch = FetchType.LAZY)
    @JoinColumn(name = "process_id", referencedColumnName = "vc_process_id", foreignKey = @ForeignKey(name = "none", value = ConstraintMode.NO_CONSTRAINT))
    List<FlowFormTestRelateRequirement> requirementList;

//    @ApiModelProperty(value = "需求标题")
//    @Column(name = "vc_requirement_title", columnDefinition = "varchar(60) comment '需求标题'")
//    private String requirementTitle;
//
//    @ApiModelProperty(value = "需求id")
//    @Column(name = "vc_requirement_id", columnDefinition = "varchar(60) comment '需求id'")
//    private String requirementId;

    /**
     * 系统名称
     */
    @ApiModelProperty(value = "所属系统")
    @Column(name = "system_name", columnDefinition = "varchar(200) comment '所属系统，从it网关取'")
    private String systemName;

    /**
     * 系统代码
     */
    @ApiModelProperty(value = "系统代码")
    @Column(name = "system_code", columnDefinition = "varchar(30) comment '系统名称，从it网关取，后续关联团队人员'")
    private String systemCode;

    @ApiModelProperty(value = "需求负责人oa")
    @Column(name = "vc_requirement_manager", columnDefinition = "varchar(60) comment '需求负责人oa账号'")
    private String requirementManager;
    @ApiModelProperty(value = "发起人姓名")
    @Column(name = "flow_create_operator_name", columnDefinition = "varchar(30) comment '发起人姓名'")
    String flowCreateOperatorName;

    @ApiModelProperty(value = "部署文件")
    @Column(name = "demand_online_doc_id_list", columnDefinition = "varchar(300) comment '需求报告附件列表'")
    private String demandOnlineDocIdList;

    @ApiModelProperty(value = "部署文件")
    @Transient
    private List<Appendix> demandOnlineDocList;

    @ApiModelProperty(value = "sonar文件")
    @Column(name = "sonar_doc_id_list", columnDefinition = "varchar(300) comment 'sonar文件'")
    private String sonarDocIdList;

    @ApiModelProperty(value = "sonar附件")
    @Transient
    private List<Appendix> sonarDocList;

    @ApiModelProperty(value = "发起人账号oa")
    @Column(name = "flow_create_operator_account", columnDefinition = "varchar(30) comment '发起人账户'")
    String flowCreateOperatorAccount;
    @ApiModelProperty(value = "发起人部门名称")
    @Column(name = "flow_creator_department", columnDefinition = "varchar(30) comment '发起人部门名称'")
    String flowCreatorDepartment;

    /**
     *系统管理员账号oa
     */
    @ApiModelProperty(value = "项目经理账号oa")
    @Column(name = "system_manager_account", columnDefinition = "varchar(30) comment '项目经理账户'")
    private String systemManager;

    @ApiModelProperty(value = "发起时间")
    @Column(name = "dt_process_create_time", columnDefinition = "datetime comment '发起时间'")
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @JsonSerialize(using = LocalDateTimeSerializer.class)
    @JsonDeserialize(using = LocalDateTimeDeserializer.class)
    private LocalDateTime processCreateTime;

    @ApiModelProperty(value = "更新时间")
    @Column(name = "dt_update_time", columnDefinition = "datetime comment '更新时间'")
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @JsonSerialize(using = LocalDateTimeSerializer.class)
    @JsonDeserialize(using = LocalDateTimeDeserializer.class)
    protected LocalDateTime updateTime;

    // 1 已完成  0 进行中
    //每一个测试人员节点通过后 查询当前测试相关的测试用例是否通过
    // 全部通过则设置为已完成 否则进行中
    //后期可修改为比例字符串  2/10完成
    @ApiModelProperty(value = "测试流程状态")
    @Column(name = "vc_testprocess_status", columnDefinition = "varchar(10) comment '测试流程状态'")
    private String testProcessStatus;

    @ApiModelProperty(value = "测试用例列表")
    @OneToMany(cascade = CascadeType.ALL,fetch = FetchType.LAZY)
    @JoinColumn(name = "l_test_task_id", referencedColumnName = "l_id", foreignKey = @ForeignKey(name = "none", value = ConstraintMode.NO_CONSTRAINT))
    private List<RequirementTeskCase> testCaseList;

    @ApiModelProperty(value = "发版分支列表")
    @OneToMany(cascade = CascadeType.ALL,fetch = FetchType.LAZY)
    @JoinColumn(name = "branch_id", referencedColumnName = "l_id", foreignKey = @ForeignKey(name = "none", value = ConstraintMode.NO_CONSTRAINT))
    private List<RequirementDeplolyBranch> deplolyBranchList;
}
